#include "point.h"
#include "route.h"

Route::Route(void):
    id(0), name(cUNNAMED), fileList(), pointList()
{}

Route::Route(const QString& aName, const unsigned long& aID):
    id(aID), name(aName), fileList(), pointList()
{}

Route::~Route()
{
    name.clear();
    fileList.clear();
    pointList.clear();
}

void Route::ClearRoute(void)
{
    name = cUNNAMED;
    fileList.clear();
    pointList.clear();
}

bool Route::SetName(const QString& aName)
{
    if(!aName.isEmpty())
    {
        name = aName;
        return true;
    }
    else
        return false;
}

QString Route::GetName(void) const
{
    return name;
}

void Route::SetID(const unsigned long& aID)
{
    id = aID;
}

unsigned long Route::GetID(void) const
{
    return id;
}

void Route::AddPoint(const unsigned long& aID)
{
    pointList.push_back(aID);
}

unsigned long Route::GetPointCount(void) const
{
    return pointList.size();
}

unsigned long Route::GetPoint(const int& aNumber) const
{
    if(aNumber >= 0 && aNumber < pointList.size())
        return pointList[aNumber];
    return NULL;
}

bool Route::RemovePoint(const unsigned long &aID)
{
    int N = pointList.size();
    for(int i = 0; i < N; ++i)
        if(pointList[i] == aID)
        {
            pointList.removeAt(i);
            return true;
        }
    return false;
}

bool Route::IsPointBelong(const unsigned long &aID) const
{
    int N = pointList.size();
    for(int i = 0; i < N; ++i)
        if(pointList[i] == aID)
            return true;
    return false;
}

QList <unsigned long> Route::GetPointList(void) const
{
    return pointList;
}

bool Route::AddFile(const QString& aFile)
{
    if(aFile.compare(""))
    {
        fileList.push_back(const_cast <QString&> (aFile));
        return true;
    }
    else
        return false;
}

unsigned long Route::GetFileCount(void) const
{
    return fileList.size();
}

QString Route::GetFileName(const int& aNumber) const
{
    if(aNumber >= 0 && aNumber < fileList.size())
        return fileList[aNumber];
    return NULL;
}

QList <QString> Route::GetFileList(void) const
{
    return fileList;
}

void Route::DeleteFile(const int& aNumber = 0)
{
    if(aNumber >= 0 && aNumber < fileList.size())
        fileList.removeAt(aNumber);
}
